#include <stdio.h>
#include <string.h>
#include <math.h>

char map[1600][1600];
char sixteen[]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
char set[600*600];
int jishu;
int num;

void draw(int n,int x,int y)
{
	int i,j,k;

	for(i=0;i<=3;i++)
	{
		if(set[jishu]=='Q')
		{
			jishu++;
			draw(n/2,x+(i/2)*n,y+(i%2)*n);
		}
		else
		{
			for(j=x+(i/2)*n;j<=x+(i/2)*n+n-1;j++)
			{
				for(k=y+(i%2)*n;k<=y+(i%2)*n+n-1;k++)
				{
					map[j][k]=set[jishu];
				}
			}
			jishu++;
		}
	}
}

void output(void)
{
	int i,j;
	int pix,ord;

	pix=0;
	ord=0;
	for(i=0;i<=num-1;i++)
	{
		for(j=0;j<=num-1;j++)
		{
			if(map[i][j]=='B')
			{
				pix+=(int)pow(2,j%8);
			}
			ord++;
			if(ord==8)
			{
				printf("0x%c%c,",sixteen[pix/16],sixteen[pix%16]);
				ord=0;
				pix=0;
			}
		}
		if(ord)
		{
			printf("0x%c%c,",sixteen[pix/16],sixteen[pix%16]);
			ord=0;
			pix=0;
		}
		printf("\n");
	}
	printf("};");
}

int main(void)
{
//	freopen("1.txt","r",stdin);
	//while(scanf("%d",&num)!=EOF)
	{
		scanf("%d",&num);
		scanf("%s",set);
		jishu=0;
		printf("#define quadtree_width %d\n#define quadtree_height %d\nstatic char quadtree_bits[] = {\n",num,num);
		draw(num,0,0);
		output();
		printf("\n");
	}
	return 0;
}
